package com.cars.ui.servlets;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cars.dto.Product;
import com.cars.service.InventoryService;

/**
 * Servlet implementation class SerachProductLineServlet
 */
@WebServlet("/searchByproductLine")
public class SerachProductLineServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	InventoryService inventoryService = null;

	@Override
	public void init() throws ServletException {
		// TODO Auto-generated method stub
		super.init();
		inventoryService = new InventoryService();
	}

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public SerachProductLineServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		String productLine = request.getParameter("productLine");
		RequestDispatcher dispatcher = request
				.getRequestDispatcher("search.jsp");

		request.setAttribute("errorMessageStatus", "hide");
		request.setAttribute("errorMessage", null);
		List<Product> productsList = inventoryService
				.getProductsByProductLine(productLine);
		request.setAttribute("productsList", productsList);
		dispatcher.forward(request, response);

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
